package com.hp.service.Impl;

import com.hp.mapper.CategoryMapper;
import com.hp.pojo.Category;
import com.hp.service.CategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Resource
    private CategoryMapper categoryMapper;


    @Override
    public List<Category> findList(int parentId) {
        return categoryMapper.findList(parentId);
    }

    @Override
    public List<Category> findAll() {
        return categoryMapper.findAll();
    }

    @Override
    public void add(Category category) {
        categoryMapper.add(category);
    }

    @Override
    public Category findById(int id) {
        return categoryMapper.findById(id);
    }

    @Override
    public void update(Category category) {
        categoryMapper.update(category);
    }

    @Override
    public void delete(int id) {
        List<Category> list = categoryMapper.findList(id);

        if (list.size()>0){
            categoryMapper.deleteParentId(id);
        }
        categoryMapper.delete(id);
    }
}
